//
//  RemarkCell.m
//  KiklinkApp
//
//  Created by LJC on 14-10-9.
//  Copyright (c) 2014年 Kiklink. All rights reserved.
//

#import "RemarkCell.h"
#import "ImagesManager.h"

#import "UIImageView+WebCache.h"

@implementation RemarkCell

- (void)awakeFromNib
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)loadData
{
    self.name.text = @"丁老二";
    
    ImagesManager *imagesManager = [ImagesManager sharedImagesManager];
    self.star1.image = [imagesManager starHighlight];
    self.star2.image = [imagesManager starHighlight];
    self.star3.image = [imagesManager starHighlight];
    self.star4.image = [imagesManager star];
    self.star5.image = [imagesManager star];
    
    self.date.text = @"2014-09-25";
    self.time.text = @"15:15:15";
    self.remark.text = @"啊实打实的久爱时空就换个卡上的的闪光灯是第十个合法进口发饰发呵呵阿斯顿全文人啊实打实的久爱时空就换个卡上的的闪光灯是第十个合法进口发饰发呵呵阿斯顿全文人";
}

- (void)loadDataWithRemark:(Comment *)comment
{
    self.name.text = comment.username;
    
    ImagesManager *imagesManager = [ImagesManager sharedImagesManager];
    if ([comment.point isEqualToNumber:@2]) {
        self.star1.image = [imagesManager starHighlight];
        self.star2.image = [imagesManager star];
        self.star3.image = [imagesManager star];
        self.star4.image = [imagesManager star];
        self.star5.image = [imagesManager star];
    } else if ([comment.point isEqualToNumber:@4]) {
        self.star1.image = [imagesManager starHighlight];
        self.star2.image = [imagesManager starHighlight];
        self.star3.image = [imagesManager star];
        self.star4.image = [imagesManager star];
        self.star5.image = [imagesManager star];
    } else if ([comment.point isEqualToNumber:@6]) {
        self.star1.image = [imagesManager starHighlight];
        self.star2.image = [imagesManager starHighlight];
        self.star3.image = [imagesManager starHighlight];
        self.star4.image = [imagesManager star];
        self.star5.image = [imagesManager star];
    } else if ([comment.point isEqualToNumber:@8]) {
        self.star1.image = [imagesManager starHighlight];
        self.star2.image = [imagesManager starHighlight];
        self.star3.image = [imagesManager starHighlight];
        self.star4.image = [imagesManager starHighlight];
        self.star5.image = [imagesManager star];
    } else if ([comment.point isEqualToNumber:@10]) {
        self.star1.image = [imagesManager starHighlight];
        self.star2.image = [imagesManager starHighlight];
        self.star3.image = [imagesManager starHighlight];
        self.star4.image = [imagesManager starHighlight];
        self.star5.image = [imagesManager starHighlight];
    }
    
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"YYYY-MM-dd"];
    
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [timeFormatter setDateStyle:NSDateFormatterMediumStyle];
    [timeFormatter setTimeStyle:NSDateFormatterShortStyle];
    [timeFormatter setDateFormat:@"HH:mm:ss"];
    
    NSDate *commentDate = [NSDate dateWithTimeIntervalSince1970:(long long)(comment.createtimelong/1000)];
    NSString *commentDateStr = [dateFormatter stringFromDate:commentDate];
    NSString *commentTimeStr = [timeFormatter stringFromDate:commentDate];
    
    self.date.text = commentDateStr;
    self.time.text = commentTimeStr;
    self.remark.text = comment.comment;
    
    self.portrait.clipsToBounds = YES;
    [self.portrait sd_setImageWithURL:[NSURL URLWithString:[Base_Url stringByAppendingString:comment.userphoto]] placeholderImage:[UIImage imageNamed:@"remarkPortrait.png"]];
}

+ (CGFloat)cellHeight:(Comment *)comment
{
    NSDictionary * attributedDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13.0], NSFontAttributeName, nil];
    CGRect newDescriptionRect = [comment.comment boundingRectWithSize:CGSizeMake(ScreenWidth-30, 20000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributedDic context:nil];
    return newDescriptionRect.size.height + 94;
}

@end
